Census Data

Community
analysis
Rstudio
Published

February 28, 2022

Show the code
## USE GEO_JOIN TO COMBINE SPATIAL DATA AND OTHER DATA FRAMES

joinOR<- geo_join(or_tracts, or, 
                 by_sp="GEOID", by_df="GEOID")

## USE TMAP PACKAGE
tm_shape(joinOR)+
  tm_fill("estimate", style = "quantile", n=7, palette = "Greens")+
  tm_legend(bg.color="white", bg.alpha=0.6)+
  tm_style("gray")

Show the code
## SET GEOMETRY
oregon <- get_acs(geography = "tract", year=this.year,
               state = "OR",
               variables = "B25077_001E",
               geometry = TRUE)

#Plotting with MAPVIEW 
mapview(oregon, zcol = "estimate", legend = TRUE, 
        lwd=.25)
Show the code
## Plotting with LEAFLET

## Leaflet with reactive
pal<-colorNumeric("Greens", domain=0:ceiling(max(oregon$estimate, na.rm=TRUE)))
popup<-paste("Tract: ", as.character(substring(oregon$GEOID, 6, 11)), "<br>",
             "Median Home Value: ", as.character(oregon$estimate))
leaflet()%>%
  addProviderTiles("CartoDB.Positron")%>%
  addPolygons(data=oregon,
              fillColor= ~pal(oregon$estimate),
              fillOpacity = 0.7,
              weight = 0.4,
              smoothFactor = 0.2,
              popup = popup)